<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JohnsonSmile的博客</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    {{template "comm/link.html"}}
    <style>
        .w-e-toolbar {
            flex-wrap: wrap;
            font-size: 14px;
        }
    </style>
</head>
<body class="lay-blog">
{{template "comm/header.html" .}}
<div class="container-wrap">
    <div class="container">
        <div class="contar-wrap">
            <div class="container-panel">
                <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                    <ul class="layui-tab-title">
                        <li class="layui-this">新增文章</li>
                    </ul>
                    <div class="layui-tab-content">
                        <form class="layui-form layui-form-pane" action="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">标题</label>
                                <div class="layui-input-block">
                                    <input type="text" name="title" required=""
                                           value="{{.note.Title}}"
                                           lay-verify="required" placeholder="请输入标题"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item layui-form-text">
                                <div class="layui-input-block">
                                    <div id="edit" style="background: #fff;">{{if .note }}{{str2html .note.Content}}{{end}}</div>
                                </div>
                            </div>

                            {{/*<div class="layui-form-item">*/}}
                                {{/*<input type="hidden" id="files" name="files" value="{{.note.Files}}">*/}}
                                {{/*<div class="layui-upload">*/}}
                                    {{/*<button type="button" class="layui-btn layui-btn-normal"*/}}
                                            {{/*id="testList">*/}}
                                        {{/*选择附件*/}}
                                    {{/*</button>*/}}
                                    {{/*<div class="layui-upload-list">*/}}
                                        {{/*<table class="layui-table">*/}}
                                            {{/*<thead>*/}}
                                            {{/*<tr>*/}}
                                                {{/*<th>文件名</th>*/}}
                                                {{/*<th>大小</th>*/}}
                                                {{/*<th>状态</th>*/}}
                                                {{/*<th>操作</th>*/}}
                                            {{/*</tr>*/}}
                                            {{/*</thead>*/}}
                                            {{/*<tbody id="demoList"></tbody>*/}}
                                        {{/*</table>*/}}
                                    {{/*</div>*/}}
                                    {{/*<button type="button" class="layui-btn" id="testListAction">开始上传</button>*/}}
                                {{/*</div>*/}}
                            {{/*</div>*/}}
                            <div class="layui-form-item">
                                <button class="layui-btn"
                                        lay-submit=""
                                        lay-filter="save">提交
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{{template "comm/footer.html"}}
<script src="/static/lib/wangEditor.js"></script>

<script>
    //Demo
    layui.use(['form', "jquery"], function () {
        var form = layui.form;
        $ = layui.jquery;

        //监听提交
        var E = window.wangEditor;
        var editor = new E('#edit');
        editor.create();
        // 关闭粘贴样式的过滤
        editor.customConfig.pasteFilterStyle = false;
        editor.customConfig.zIndex = 1;
        // 使用 base64 保存图片
        editor.customConfig.uploadImgShowBase64 = true;
        form.on('submit(save)', function (data) {
            data.field.content = editor.txt.html();
            $.post("/note/save/{{.key}}", data.field, function (resp) {
                console.log(resp);
                if (resp.code == 0) {
                    layer.msg("保存成功!");
                    if (resp.action) {
                        setTimeout(function () {
                            window.location.href = resp.action;
                        }, 300);
                    }
                } else {
                    layer.msg("保存失败!" + resp.msg);
                }
            }, "json").error(function () {
                layer.msg("网络异常！");
            });
            return false;
        });

    });
</script>
</body>
</html>